﻿var uploadButtonImg = 'theme/default/images/upload_'+ lang +'.png';

$(function(){
	//高亮
	$('#description').focus(function(){
		$(this).addClass("highLight")		 
	}).blur(function(){
		$(this).removeClass("highLight") 
	});
	
	mediaThumb();
	$('#userIntoForm').submit(function(){submitDate(this); return false});
	strLimit('#description','#descriptionNum',800,1);
	cancleFile('div.uploadifyQueueItem div.cancel a','#fileQueue .uploadifyQueueItem');
});

 

function mediaThumb(){
	$("#mediaThumb").uploadify({
		'uploader'       : root_path+'upload/scripts/uploadify.swf',
		'script'         : root_path+'?option=uploadFileAction%26type=action%26do=uploadUserFace%26time='+ time(),
		'cancelImg'      : 'upload/images/cancel.png',
		'folder'         : 'tmp',
		'queueID'        : 'faceSmallQueue',
		'auto'           : true,
		'multi'          : false ,
		'queueSizeLimit' : 1 ,
		'fileDesc' 		 : '*.jpg;*.png;', 
		'fileExt'		 : '*.jpg;*.png;', 
		'sizeLimit'		 :  5 * 1024 * 1024  , //byte
		'width'			 :120,
		'height'		 :30,
		'buttonImg': uploadButtonImg ,
		onComplete: function (evt, queueID, fileObj, response, data) {
			$('#facePhoto').html(response);
			$('#nav .navFace img').attr('src',$('#facePhoto img:last').attr('src'));
			$('#facePhoto img:last')
		},
		onSelect : function(){
		}
	});

};

function submitDate(obj){
	var $obj = $(obj);
	var $submit = $obj.find('input[type=submit]')
	$submit.attr('disabled',true);
	var url = $obj.attr('action');
	var $face = $('#facePhoto img');
	var faceUrl = $face.eq(0).attr('url') +'|'+  $face.eq(1).attr('url');	
	var sendData = {'faceUrl': faceUrl,'description':$('#description').val(),'dateType':'ajax'};
	$.post(url,sendData,function(data){
		if('ok'== data.status){
			$.openWin({'msg':data.msg,'time':1500});
			setTimeout(function(){window.location.href= data.url;},1600);
		}
		else
			alert(data.msg);
		$submit.attr('disabled',false);
	},'json');
};


function cancleFile(obj,creatOrderObj){
	$(obj).live('click',function(){
		$(this).parent().parent().animate({'opacity':'hide','height':0},'slow',function(){
			$(this).remove();
			creatOrderNum(creatOrderObj);
		});
		return false;
	});
};